<template>
  <div id="head-menu" :class="hasKeys?'head-menu-hasKeys':''">
    <div class="yh-layout-box">
      <div class="menu-logo cursor" @click="routeToPath('/','mallplus')">
        <img class="yh-middle" src="~assets/images/meal/logo.png">
      </div>
      <ul class="menu-list">
        <li v-for="(i, index) in menuList" :class="i.ide == ideName?'active':''" @click="routeToPath(i.url, 'mall',i.ide == 'merchants'?'new':'')">{{ i.name }}</li>
      </ul>
      <div :class="hasKeys?'hasKeys menu-search':'menu-search'">
        <div class="search-main">
          <div class="search-select">
            <el-dropdown  trigger="click" @command="handleCommand">
              <span class="el-dropdown-link">
                <span class="searchActive">{{searchActive}}</span>  <i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-for="(i, idx) in searchList" :command="i.value" :key="idx">{{ i.label }}</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
          </div>
          <div class="search-input">
            <el-input v-if="searchActive == '商品'" :placeholder="searchList[0].tips" v-model="searchKW" @keyup.enter.native="submitSearch"></el-input>
            <el-input v-else :placeholder="searchList[1].tips" v-model="searchKW" @keyup.enter.native="submitSearch"></el-input>
          </div>
          <div class="search-btn" @click="submitSearch">
            <img class="yh-middle" src="~assets/images/layouts/headMenu/search.png">
          </div>
        </div>
        <div class="search-key" v-if="hasKeys">
          <a @click="routeToPath('/search/product?kw='+i, 'mall', 'new')" v-for="(i, index) in searchKeys" :key="index">{{i}}</a>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
export default {
  props: ['ideName', 'kw', 'pageFrom', 'hasKeys'],
  data() {
    return {
      searchList: [{
        label: '商品',
        value: 'goods',
        tips: '请输入商品或品牌名称'
      },{
        label: '云工厂',
        value: 'factory',
        tips: '请输入云工厂名称或品牌名称'
      }],
      searchActive: null,
      searchKW: null,
      kwFrom: null,
      // kwFrom: this.getUrlParams('factoryName'),
      menuList: [{
        name: '首页',
        url: '/',
        ide: 'home'
      },{
        name: '招商入驻',
        url: '/merchants/package',
        ide: 'merchants'
      },
      {
        name: '品牌中心',
        url: '/brand',
        ide: 'brand'
      },
      {
        name: '帮助中心',
        url: '/help',
        ide: ''
      },{
        name: '关于我们',
        url: '/about',
        ide: 'about'
      }],
      searchKeys:['钳类工具', '不锈钢', '五金配件', '角磨机', '安全鞋', '阀片', '水龙头'],
    }
  },
  created() {
    if(this.kwFrom){
      this.searchActive = this.searchList[1].label;
      this.searchKW=this.kwFrom;
    }else{
      this.searchActive = this.searchList[0].label;
      this.searchKW=this.kw;
    }
  },
  methods: {
    handleCommand(e) {
      for (var index in this.searchList) {
        if (this.searchList[index].value == e) {
          this.searchActive = this.searchList[index].label
        }
      }
    },
    submitSearch(){
      if(!this.searchKW && this.searchActive == '商品' && this.pageFrom != 'product' || !this.searchKW) {
        return false;
      }
      if (this.searchActive == '商品') {
        this.routeToPath('/search/product?kw=' + this.searchKW,'mall')
      } else {
        this.routeToPath('/search/shop?factoryName=' + this.searchKW,'mall')
      }
    }
  }
}
</script>

<style scoped lang="scss">
#head-menu{
  overflow: hidden;
  background-color: #FFF;
  padding-top: 16px;
  min-width: 1200px;
  padding-bottom: 19px;
  .menu-logo{
    float: left;
  }
  .menu-list{
    float: left;
    margin-left: 92px;
    li{
      float: left;
      margin-right: 35px;
      font-size: 16px;
      line-height: 50px;
      cursor: pointer;
    }
    .active{
      color: #255B8A;
      font-weight: 600;
    }
  }
  .menu-search{
    float: right;
    margin-top: 8px;
    .search-key{
      padding-top: 10px;
      a{
        float: left;
        margin:0 10px;
        font-size: 12px;
        color: #666;
        &:hover{
          color: #255B8B;
        }
      }
    }
    .search-main{
      overflow: hidden;
    }
    .search-main div {
      float: left;
    }
    .search-select{
      background-color: #F0F0F0;
      height: 36px;
      line-height: 36px;
      border-radius: 15px 0 0 0;
      padding-left: 20px;
      padding-right: 10px;
      .searchActive{
        display: inline-block;
        width: 40px;
      }
      cursor: pointer;
      .el-dropdown-link{
        font-size: 12px;
      }
    }
  }
  .hasKeys{
    margin-top: 0;
  }
}
#head-menu.head-menu-hasKeys{
  padding-bottom: 17px;
  .menu-logo{
    margin-top: 5px;
  }
  .menu-list li{
    line-height: 56px;
  }
}
</style>

<style lang="scss">
.search-input{
  .el-input__inner{
    background-color: #F0F0F0;
    width: 280px;
    padding: 0 10px;
    height: 36px;
    border: 0;
    font-size: 12px;
    border-radius: 0;
  }

}
.search-select{
  .el-dropdown{
    min-width: 60px;
  }
}

.search-main{

  .el-dropdown-menu__item{
    padding: 0 18px;
  }
}
.el-dropdown-menu{
  padding: 0;
  overflow: inherit;
}
</style>
